package ltd.ninefish.framework.core.utils;

import com.github.pagehelper.PageHelper;
import ltd.ninefish.framework.core.utils.database.SqlUtil;
import ltd.ninefish.framework.core.web.page.PageInfo;
import ltd.ninefish.framework.core.web.page.PageInfoHandler;

/**
 * @author zhaoxiubin
 * create-time 2023-12-16 15:56
 * description 分页工具
 **/

public class PageUtil extends PageHelper
{
    /**
     * 设置请求分页数据
     */
    public static void startPage()
    {
        PageInfo pageDomain = PageInfoHandler.getRequestPageInfo();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
        Boolean reasonable = pageDomain.getReasonable();
        PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
    }

    /**
     * 清理分页的线程变量
     */
    public static void clearPage()
    {
        PageHelper.clearPage();
    }
}
